package com.xpec.c4.service.module.datacenter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ms.service.module.datacenterlite.CentralDataAsync;
import com.ms.service.telnet.STelnetCmd;
import com.xpec.c4.game.time.TimeConstants;
import com.xpec.c4.service.module.BasicServiceModule;
import com.xpec.c4.service.module.datacenter.account.AccountDataManager;
import com.xpec.c4.service.module.datacenter.account.AccountDataProcess;
import com.xpec.c4.service.module.datacenter.centralcmd.CentralCommandAction;
import com.xpec.c4.service.module.datacenter.player.PlayerDataManager;
import com.xpec.c4.service.module.datacenter.player.PlayerDataProcess;

/**
 * Data Center 模块<br>
 * 
 * @author yangbingyan
 *
 */
public class DataCenterModule extends BasicServiceModule{
	
	private static final long TIMER_LOOP_INTERVAL =  60 * TimeConstants.MILLI_SECOND_PRE_SECOND;
	
	private static final Log log = LogFactory.getLog(DataCenterModule.class);
	
	/**
	 * 帐号 
	 */
	private AccountDataManager accountDataManager = new AccountDataManager(this);
	
	/**
	 * 玩家
	 */
	private PlayerDataManager playerDataManager = new PlayerDataManager(this);

	/**
	 * 开始
	 * 
	 * @return
	 *
	 */
	@Override
	public boolean startup(){
		registerJmxInfo();
		return super.startup();
	}
	
	/**
	 * 停止
	 * 
	 * @return
	 */
	@Override
	public void shutdown(){
		
		super.shutdown();
	}

	/**
	 * 初始化
	 * 
	 * @return
	 *
	 */
	@Override
	public void init(){
		
		
		super.init();

		// 注册相关的class给Action使用
		registerActionClass(AccountDataProcess.class);
		registerActionClass(PlayerDataProcess.class);
		registerActionClass(CentralCommandAction.class);
		accountDataManager.init();

	}

	public boolean addCentralAsyncCommand(CentralDataAsync obj) {
		
		if(obj == null){
			return false;
		}

		//判斷是否超過預設 threadID, 取正值
		int key = obj.getQueueID();
		if(key != 0){
			int hash = key % (asyncTaskQueueCount-2);
			obj.setQueueID((hash < 0) ? -hash : hash);
		}
		
		return super.addAsyncCommand(obj);
	}
	
	/**
	 * 
	 * @param objInfo
	 */
	public void moduleSetting(Object objInfo){
		if(objInfo == null){
			return;
		}
	}

	@Override
	public void procTelnetCommand(STelnetCmd obj) {
		// TODO Auto-generated method stub
	}

	public AccountDataManager getAccountDataManager() {
		return accountDataManager;
	}

	public PlayerDataManager getPlayerDataManager() {
		return playerDataManager;
	}

	@Override
	public void procThrowException(Object obj) {
		// TODO Auto-generated method stub
		
	}

}
